<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <!--{include file='comm/header.tpl'}-->
    <title>活动页管理</title>
</head>
<body>

<div class="container">

    <div class="comm_content">

            <div class="search-box">
                <div style="position:relative">
                    <form class="form-inline" id="search_form" onsubmit="return false;">
                        <table>
                            <tbody>
                            <tr>
                                <td>
                                    <span>活动页标题：<input type="text" class="form-control w150" id="contentTitle" name="contentTitle" /></span>
                                    <span>活动页关键字：<input type="text" class="form-control w150" id="searchKeys" name="searchKeys" /></span>
                                    <!--add by allen.qiang 2015-01-13 FUN-BK-0045-PC_WAP首页底下广告位按城市维护 start-->
                                    <span>城市：
                                        <select class="form-control input-sm" name="cityID" id="cityID">
                                            <option value="">请选择</option>
                                            <!--{if isset($city_array)}-->
                                            <!--{foreach from=$city_array item=city}-->
                                            <option value="<!--{$city.id}-->"><!--{$city.name}--></option>
                                            <!--{/foreach}-->
                                            <!--{/if}-->
                                        </select>
                                    </span>
                                    <span>状态：
                                        <select class="form-control input-sm" name="useFlg" id="useFlg">
                                            <option value="">请选择</option>
                                            <option value="1">启用</option>
                                            <option value="0">禁用</option>
                                        </select>
                                    </span>
                                    <!--add by allen.qiang 2015-01-13 FUN-BK-0045-PC_WAP首页底下广告位按城市维护 end-->
                                    <span><input type="button" value="查询" class="btn btn-primary" onclick="content.search();" /></span>
                                    <span><input type="button" value="重置" class="btn btn-warning" onclick="content.reset();" /></span>
                                </td>
                            </tr>
                            </tbody>
                        </table>
                    </form>
                </div>
            </div>

            <table id="flex" style="display:none"></table>

        </div>

</div>

<script type="text/javascript">
    $("#flex").flexigrid({
        url:"/invokingAjax-backend/content/center.ajax?operFlg=1",
        dataType: "json",
        colModel : [
        	<!--{if $edit_permission}-->
           		{display: "操作", width : 120, align: "center"},
            <!--{/if}-->
            //add by allen.qiang 2015-01-13 FUN-BK-0045-PC_WAP首页底下广告位按城市维护 ---start
            {display: "城市", width : 80},
            //add by allen.qiang 2015-01-13 FUN-BK-0045-PC_WAP首页底下广告位按城市维护 ---end
            {display: "活动页编号", name : "contentID", width : 100, sortable : true},
            {display: "活动页标题", width : 260},
            {display: "活动页关键字", width : 200},
            {display: "排列序号", width : 80},
            {display: "创建时间", width : 200, align: "center"},
            {display: "状态", width : 80, align: "center"}
        ],
        <!--{if $edit_permission}-->
	        buttons : [
	            {name: "添加", bclass: "add", onpress : "content.add"},
	            {separator: true},
	            {name: "删除", bclass: "delete", onpress : "content.deleteContent"},
                {separator: true},
                {name: "全选", bclass: "checkAll", onpress : "E.checkAllList"},
                {separator: true},
                {name: "取消全选", bclass: "cancelCheckAll", onpress : "E.cancelCheckAllList"}
	        ],
        <!--{/if}-->
        sortname: "contentID",
        sortorder: "desc",
        usepager: true,
        rp: 10,
        useRp: true,
        showTableToggleBtn: true,
        onSubmit: function() {
            var dt = $('#search_form').serializeArray();
            $("#flex").flexOptions({params: dt});
            return true;
        }
    });

    var content = {
    	
    	publish:function (uid , publish_url) {
			this.publish_uid = uid;
			this.publish_url = publish_url;
			
			E.confirm("您确认要发布此活动页管理缓存吗？", function() {
                var link = "/shop/contentCenter.php?id=" + uid +"&"+ publish_url + '&subsite=shop';
                window.open(link,"_blank") ;
            });
		},

		preview:function (uid , preview_url){
			var link = "/shop/contentCenter.php?id=" + uid +"&"+ preview_url + '&subsite=shop' ;
			window.open(link,"_blank") ;
		},

        delete_str: "",

        //搜索内容
        search: function() {
            var dt = $('#search_form').serializeArray();
            $("#flex").flexOptions({params: dt}).flexReload();
        },

        //重置内容
        reset: function() {
            $('#contentTitle').val('');
            $('#searchKeys').val('');
            //add by allen.qiang 2015-01-13 FUN-BK-0045-PC_WAP首页底下广告位按城市维护 ---start
            $('#cityID').val('');
            $('#useFlg').val('');
            //add by allen.qiang 2015-01-13 FUN-BK-0045-PC_WAP首页底下广告位按城市维护 ---end
            var dt = $('#search_form').serializeArray();
            $("#flex").flexOptions({params: dt}).flexReload();
        },

        //添加内容
        add: function() {
            E.open("/quanliadmin/app/content/contentCenter.pscript?operFlg=2", "", {height: 600,width: 1024, top: 50, left: 150});
        },
		
        //状态标记
        useFlg: '',
        
        //内容ID
        contentID:'',
        
        //启用禁用内容
        setUse: function( contentID, useFlg ){
        	
        	if (!E.isNum(contentID)) {
        		E.alert('参数错误');
        		return false;
        	}
        	
        	//判断参数
        	if ( useFlg != '0' && useFlg != '1') {
        		E.alert('参数错误');
        		return false;
        	}
        	
        	this.useFlg = useFlg;
        	this.contentID = contentID;
        	
        	if (useFlg == '1') { //当前启用
        		E.confirm("您确认要禁用选中的内容吗？", "content.setUseConfirm");
        	} else {
        		content.setUseConfirm();
        	}
        	
        },
        
        //状态标记设置确认
        setUseConfirm: function(){
        	if (this.useFlg != '0' && this.useFlg != '1') {
        		E.alert('参数错误');
        		return false;
        	}
        	
        	E.ajax_post({
        		url:'/invokingAjax-backend/content/center.ajax?operFlg=100&act=change',
        		data:{
        			contentID: this.contentID,
        			useFlg: this.useFlg
        		},
        		call:'content.setResult'
        	});
        },
        
        //设置内容标记结果
        setResult: function( o ){
        	if ( o.code == 200 ) {
        		E.alert(o.message,2);
        		if (this.useFlg == '1') {
        			$('#conentStatus_' + this.contentID).attr('onclick','content.setUse(' + this.contentID + ',0); return false;').text('禁用');
        		} else {
        			$('#conentStatus_' + this.contentID).attr('onclick','content.setUse(' + this.contentID + ',1); return false;').text('启用');
        		}
        	} else {
        		E.alert(o.message);
        	}
        },
        
        //删除内容
        deleteContent: function() {
            this.delete_str = "";
            $.each($("#flex").find("tr"), function(k, v) {
                if ($(v).hasClass("trSelected")) {
                    content.delete_str += "_" + $(v).attr("id").replace("row", "");
                }
            });

            if (this.delete_str == "")
                E.alert("请选择删除该条内容");
            else
                E.confirm("您确认要删除选中的内容吗？", "content.deleteConfirm");
        },

        deleteConfirm: function() {

            this.delete_str = this.delete_str.substr(1);

            E.ajax_post({
                url:'/invokingAjax-backend/content/center.ajax?operFlg=100&act=del',
                data:{
                    delete_str: content.delete_str
                },
                call:'content.deleteResult'
            });

        },

        deleteResult: function( o ) {
            if (o.code == 200) {
                E.alert(o.message, 2, "content.load");
            } else {
                E.alert(o.message);
            }
        },
		
        edit: function(contentID) {
            E.open("/quanliadmin/app/content/contentCenter.pscript?operFlg=3&contentID="+contentID, "", {height: 600,width: 1024, top: 50, left: 150});
        },

        load: function() {
            $("#flex").flexReload();
        }

    };

</script>

</body>

</html>